home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7435 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  68 lines

  1. Path: news.ov.com!news
  2. From: glenn@ov.com (Fletcher.Glenn@ov.com)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: automatic charrs
  5. Date: 26 Feb 1996 16:56:24 GMT
  6. Organization: OpenVision
  7. Message-ID: <4gsono$3uc@spanky.pls.ov.com>
  8. References: <4glp29$dsh@d2.tufts.edu>
  9. Reply-To: glenn@ov.com
  10. NNTP-Posting-Host: foghorn.pls.ov.com
  11.  
  12. In article dsh@d2.tufts.edu, rdorich@emerald.tufts.edu (Roberto Dorich) writes:
  13. >Hello,
  14. >
  15. >Could someone enlighten me, and tell me why the following program runs
  16. >just dandy using Sun's cc (3.0.1), but crashes using gcc (?) ?
  17. >
  18. >#include <stdio.h>
  19. >char *b() { return "Hello";}
  20.                     ^^^^^^^
  21. This string should be defined as const, which means that you cannot
  22. modify it.  Apparently gcc is enforcing this, and Sun's cc is not.
  23.  
  24.             Fletcher.Glenn@ov.com
  25.  
  26. >main() {
  27. >  char *a=b();
  28. >  a[0]='X';
  29. >  printf("--> %s\n",a);
  30. >}
  31. >
  32. >Esentially, gcc puts out the following assembly code:
  33. >
  34. >call b,0
  35. >nop
  36. >mov 88,%o1        // %o1 = 'X'
  37. >stb %o1, [%o0]          // a[0] = %o1
  38. >
  39. >And cc spits out the following:
  40. >
  41. >        call    b
  42. >        nop
  43. >        mov     88,%l1
  44. >        stb     %l1,[%l0+0]
  45. >
  46. >(this assembly code has been optimized by me :-/ )
  47. >
  48. >Anyway, there isn't really that much difference... but I get a seg fault
  49. >with gcc.  Why?
  50. >
  51. >Thanks!
  52. >
  53. >Roberto
  54. >
  55. >--
  56. >
  57. >Roberto Dorich               o       SKI        rdorich@ee.cornell.edu
  58. >Electrical Engineering   /=     EXTREME         rdorich@tufts.edu
  59. >Cornell University     __/__,               dorich@ptc.com
  60. >----------------------------------------------------------------------
  61.  
  62.  
  63.  
  64.  
  65.  
  66.